package com.pxmeta.app.controller.user;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pxmeta.circle.entity.dto.SignInDTO;
import com.pxmeta.common.core.domain.AjaxResult;
import com.pxmeta.common.utils.SecurityUtils;
import com.pxmeta.user.entity.SignConfig;
import com.pxmeta.user.entity.UserSignRecord;
import com.pxmeta.user.service.IUserSignRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Api(value = "用户签到",tags = "用户签到")
@Slf4j
@RequestMapping("/sign")
public class UserSignController {

    private final IUserSignRecordService userSignRecordService;


    @SaCheckLogin
    @ApiOperation("获取签到奖励列表")
    @GetMapping("/signIn")
    public AjaxResult signList(){
        Long userId = SecurityUtils.getUserId();
        List<SignConfig> list = userSignRecordService.listReward(userId);
        return AjaxResult.success(list);
    }

    @SaCheckLogin
    @ApiOperation("用户签到")
    @PostMapping("/signIn")
    public AjaxResult signIn(@RequestBody SignInDTO dto){
        Long userId = SecurityUtils.getUserId();
        userSignRecordService.signInSystem(dto.getCircleId(), userId,dto.getRewardId());
        return AjaxResult.success();
    }


}
